﻿//创建时间: 2011-1-28
//创建作者: 李 城
//功能说明: 标签解析出错时的提示
//最后修改: 2011-1-28
using System;
using System.Collections.Generic;

using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
using TRPOP.CMS.Plugin;
using System.Data;

namespace TRPOP.CMS.Template
{
    /// <summary>
    /// 标签解析出错时的提示
    /// </summary>
    internal  class TagsError
    {

        /// <summary>
        /// 错误信息的枚举值
        /// </summary>
        public enum TagsErrorAnalysis
        {
            /// <summary>
            /// 没有数据
            /// </summary>
            NotFoundData = 1,
            /// <summary>
            /// 标签不符合相关规则
            /// </summary>
            RunningError = 2,
            /// <summary>
            /// SQL语句运行错误
            /// </summary>
            SqlRunningError = 3,
            /// <summary>
            /// 执行函数时出错
            /// </summary>
            FuncRunningError = 4,
            /// <summary>
            /// 属性设置不正确
            /// </summary>
            ArrtibuteError = 5,
            /// <summary>
            /// 找不到相关的文件
            /// </summary>
            NotFoundFile = 6,
            /// <summary>
            /// 表达式格式不正确
            /// </summary>
            ExpError = 7,
            /// <summary>
            /// 没有找到变量
            /// </summary>
            NotFoundVar = 8
        }

        /// <summary>
        /// CMS错误提示
        /// </summary>
        /// <param name="oError"></param>
        /// <returns></returns>
        public static string GetTagsError(TagsErrorAnalysis oError)
        {
            string strError = "<div style=\"font-family: Arial; font-size: 12px;background-color: #FFFFE1;border: 1px dashed #CFCFCF;padding:5px;font-weight: bold;color:red;\">" +
                              " [CMS] 运行模板解析时错误  {0}" +
                              "</div>";
            switch (oError)
            {
                case TagsErrorAnalysis.NotFoundData:
                    strError = "";//string.Format(strError, "：标签返回的数据为空");
                    break;
                case TagsErrorAnalysis.RunningError:
                    strError = string.Format(strError, "：请查看是否符合标签使用规则");
                    break;
                case TagsErrorAnalysis.SqlRunningError:
                    strError = string.Format(strError, "：SQL语句运行错误");
                    break;
                case TagsErrorAnalysis.FuncRunningError:
                    strError = string.Format(strError, "：执行函数时出错");
                    break;
                case TagsErrorAnalysis.ArrtibuteError:
                    strError = string.Format(strError, "：标签属性设置不正确");
                    break;
                case TagsErrorAnalysis.NotFoundFile:
                    strError = string.Format(strError, "：根据你所指定的文件路径找不到该文件");
                    break;
                case TagsErrorAnalysis.ExpError:
                    strError = string.Format(strError, "：你所指定的表达式格式不正确");
                    break;
                case TagsErrorAnalysis.NotFoundVar:
                    strError = "";//string.Format(strError, "：没有找到你所指定的变量");
                    break;
                default:
                    strError = string.Format(strError, "");
                    return "";
            }
            return strError;
        }

        /// <summary>
        /// CMS错误提示
        /// </summary>
        /// <param name="oError"></param>
        /// <param name="strInfo"></param>
        /// <returns></returns>
        public static string GetTagsError(TagsErrorAnalysis oError, string strInfo)
        {
            if (string.IsNullOrEmpty(strInfo))
                return GetTagsError(oError);
            string strError = "<div style=\"font-family: Arial; font-size: 12px;background-color: #FFFFE1;border: 1px dashed #CFCFCF;padding:5px;font-weight: bold;color:red;\">" +
                  " [CMS] 运行模板解析时错误  {0}" +
                  "</div>";
            return string.Format(strError, "：" + strInfo);

        }

    }
}
